//
//  CustomTabBarController.m
//  中间自定义TabBar
//
//  Created by QC.L on 15/5/24.
//  Copyright (c) 2015年 QC.L. All rights reserved.
//

#import "CustomTabBarController.h"
#import "JingRoundView.h"

@interface CustomTabBarController ()<JingRoundViewDelegate>

@property (retain, nonatomic) JingRoundView *roundViewxiao;
@end

@implementation CustomTabBarController
-(void)dealloc
{
    [_roundViewxiao release];
    [super dealloc];
    
}

- (void)createNotificationCenter
{

    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(zhuanzhuan:) name:@"zhuan" object:nil];
}
- (void)zhuanzhuan:(NSNotification *)noti
{
    
    if ([noti.object isEqualToString:@"xiaokang"]) {
        [_roundViewxiao pauseRotation];
    }else if ([noti.object isEqualToString:@"jiaqing"]) {
        [_roundViewxiao startRotation];
    }
}




- (UIViewController *)viewControllerWithTabTitle:(NSString *)title image:(UIImage *)image className:(NSString *)className
{
    Class class = NSClassFromString(className);
    UIViewController *viewController = [[class alloc] init];
    viewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:image tag:0];
    return viewController;
}

- (void)addCenterButtonWithImage:(UIImage *)buttonImage highlightImage:(UIImage *)highlightImage
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.backgroundColor = [UIColor redColor];
    button.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height);
    [button setBackgroundImage:buttonImage forState:UIControlStateNormal];
    [button setBackgroundImage:highlightImage forState:UIControlStateHighlighted];
    
    
    
    CGFloat heightDifference = buttonImage.size.height - self.tabBar.frame.size.height;
    if (heightDifference < 0) {
        button.center = self.tabBar.center;
    } else {
        CGPoint center = self.tabBar.center;
        center.y = center.y - heightDifference / 2.0;
        button.center = center;
    }
    
    
}

- (void)addCenterBackButtonWithImage:(UIImage *)buttonImage highlightImage:(UIImage *)highlightImage
{
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor whiteColor];
    view.frame = CGRectMake(0, 0, buttonImage.size.width + 10, buttonImage.size.height * 1.7);
    view.layer.cornerRadius = (buttonImage.size.width + 10) / 2;
    view.layer.borderWidth = 1;
    view.tag = 1234;
    view.layer.borderColor = [UIColor colorWithRed:220 / 255.0 green:220 / 255.0 blue:220 / 255.0 alpha:1.0].CGColor;
    
    self.roundViewxiao = [[JingRoundView alloc] initWithFrame:CGRectMake(5, 5, buttonImage.size.width, buttonImage.size.height)];
    //    self.roundViewxiao.center = button1.center;
    self.roundViewxiao.delegate = self;
    self.roundViewxiao.roundImage = [UIImage imageNamed:@"7A200BDF-2E33-4925-AC63-DD24F3185993"];
    self.roundViewxiao.rotationDuration = 10.0;
    self.roundViewxiao.isPlay = NO;
    [view addSubview:_roundViewxiao];
    
    //    [view bringSubviewToFront:button1];
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    button1.frame = CGRectMake(5, 5, buttonImage.size.width, buttonImage.size.height);
    [button1 setBackgroundImage:buttonImage forState:UIControlStateNormal];
    [button1 setBackgroundImage:highlightImage forState:UIControlStateHighlighted];
    [button1 addTarget:self action:@selector(playButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.roundViewxiao addSubview:button1];
    button1.alpha = 0.1;
    button1.tag = 6789;
    view.center = self.tabBar.center;
    view.center = CGPointMake(view.center.x, view.center.y + 10);
    [self.view addSubview:view];
    
    [self createNotificationCenter];
    
}
- (void)playButtonAction:(UIButton *)button
{


    [_roundViewxiao startRotation];
    JHPlayViewController *custVc = [JHPlayViewController sharePlayerController];
    if (custVc.player.state == STKAudioPlayerStateReady) {
        [custVc beginAction:self];
    }
    else if (custVc.player.state == STKAudioPlayerStateStopped){
        [custVc beginAction:self];
    }
    [self presentViewController:custVc animated:YES completion:^{
        
    }];
    

}



    



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
